//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Windows.Data;
using System.Windows.Media;

namespace OpenLS.Drawing.UI.Internals
{
    public class LineFillPropertiesToBrushConverter: IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return GetBrush(
                StrictConverter.Convert<LineFillProperties>(values[0]), StrictConverter.Convert<ColorScheme>(values[1]));
        }
        static readonly Dictionary<Pair<LineFillProperties, ColorScheme>, Brush> _cache = new Dictionary<Pair<LineFillProperties, ColorScheme>, Brush>();
        public static Brush GetBrush(LineFillProperties lineProperties, ColorScheme colorScheme)
        {
            var key = new Pair<LineFillProperties, ColorScheme>(lineProperties, colorScheme);
            Brush result;
            if (lineProperties == null)
                return null;
            if (_cache.TryGetValue(key, out result))
                return result;
            result = lineProperties.ToBrush(colorScheme);
            _cache.Add(key, result);
            return result;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}